"""

参考网址：http://docs.sympy.org/latest/tutorial/index.html

包含的包：
    1、Gotchas：
    2、Basic Operations：
    3、Printing：
    4、Simplification：
    5、Calculus：微积分
    6、Solvers：
    7、Matrices：矩阵

"""


"""

    Part 5. Calculus

"""
# 极限
# from sympy import *
#
# x = Symbol('x')
# result = limit(sin(x)/x, x, 0)
# print(result)
# expr = x**2/exp(x)
# result = limit(expr, x, oo)
# print(result)


# 偏微分
# from sympy import *
#
# x, y, z = symbols('x y z')
# expr = exp(x*y*z)
# print(expr)
# print(expr.diff(x, y, 2, z, 4))
#
# deriv = Derivative(expr, x, y, 2, z, 4)
# print(deriv)
# print(deriv.doit())


# 全微分
# from sympy import *
#
# x, y, z = symbols('x y z')
# expr = exp(x*y*z)
#
# x_diff = expr.diff(x)
# y_diff = expr.diff(y)
# z_diff = expr.diff(z)
# print(x_diff)
# print(y_diff)
# print(z_diff)
#
# diff = x_diff + y_diff + z_diff
# print(diff)


# 一元积分
# from sympy import *
#
# x = Symbol('x')
# expr = exp(-x)
# result = integrate(expr, (x, 0, oo))
# print(result)


# 多重积分
# from sympy import *
#
# x, y = symbols('x y')
# expr = exp(-x**2 - y**2)
# result = integrate(expr, (x, -oo, oo), (y, -oo, oo))
# print(result)
#
# integ = Integral(expr, (x, -oo, oo), (y, -oo, oo))
# print(integ)
# print(integ.doit())


# 级数展开


# 有限差值


"""

    傅里叶变换

"""
from scipy.fftpack import fft, ifft
import numpy as np
import matplotlib.pyplot as plt

pi = np.pi
sin = np.sin

x = np.linspace(0, 1, 1400)
y = 7*sin(2*pi*180*x) + 2.8*sin(2*pi*390*x) + 5.1*sin(2*pi*600*x)
yy = ifft(fft(y))

yf = abs(fft(y))
yf1 = abs(fft(y)) / len(x)
yf2 = yf1[range(int(len(x)/2))]

xf = np.arange(len(y))
xf1 = xf
xf2 = xf[range(int(len(x)/2))]

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

plt.subplot(2, 3, 1)
plt.plot(x[0:50], y[0:50])
plt.title('原始波的时域图像', fontsize=10)

plt.subplot(2, 3, 2)
plt.plot(xf, yf, 'r')
plt.title('傅里叶变换获取的频率图像（一）', fontsize=10, color='#7A378B')

plt.subplot(2, 3, 3)
plt.plot(xf1, yf1, 'g')
plt.title('傅里叶变换获取的频率图像（二）', fontsize=10, color='r')

plt.subplot(2, 3, 4)
plt.plot(xf2, yf2, 'b')
plt.title('傅里叶变换获取的频率图像（三）', fontsize=10, color='#F08080')

plt.subplot(2, 3, 5)
plt.plot(x[0:50], yy[0:50], '#000000')
plt.title('原始波的傅里叶级数', fontsize=10)

plt.show()